<?php
/**
 * 
 * @authors 丛玉坤(you@example.org)
 * @date    2016-06-25 22:00:22
 * @version 一版
 */
namespace Home\Controller;
use Think\Controller;
	class YaoqingController extends Controller 
	{      	
	   public function info()
	   {
	   	if($_POST){
  // echo '<pre>';print_r($_POST);print_r($_SESSION);

$tel=$_POST['mobile'];
$User=M("User");
$uarr=$User->field('tel')->where('tel='.$tel)->find();

    if ($uarr['tel']!='') {
          
          echo "<script>
                  alert('该电话已注册，请更换后重试');
                  history.go(-1);
                </script>";
                die;
    }


  if($_POST['mobile']!=$_SESSION['mobile'] or $_POST['mobile_code']!=$_SESSION['mobile_code'] or empty($_POST['mobile']) or empty($_POST['mobile_code'])){
    exit('手机验证码输入错误。'); 
  }else{

    $_SESSION['mobile'] = '';
    $_SESSION['mobile_code'] = '';  
             $data['tel']=I('post.mobile');
             $data['yid'] = I('post.yid'); 

   
                
             array_filter($data);
               // echo "<pre>";
               // print_r ($data);
               // echo "</pre>";
            if (!empty($data)) {
          $list=M("User")->where('id='.$_SESSION['id'])->save($data);
          if ($list) {
            $this->redirect('/Yaoqing/index');
          }else{
            echo M("User")->getError();
            die('出错了！联系管理员');
            }
          }
       
    
  }
}
  function random($length = 6 , $numeric = 0) {
    PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
    if($numeric) {
      $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
    } else {
      $hash = '';
      $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
      $max = strlen($chars) - 1;
      for($i = 0; $i < $length; $i++) {
        $hash .= $chars[mt_rand(0, $max)];
      }
    }
    return $hash;
  }
  $_SESSION['send_code'] = random(6,1);

         $this->display();
	   }

     public function index()
     {   
      // unset($_SESSION);
      if ($_SESSION['id']!='') {

        $User=M("User");
        $UserInfo=$User->where('id='.$_SESSION['id'])->find();
        $this->yaoqing=$_SESSION['id'];
           if ($UserInfo['tel']=='') {
            $this->redirect("/Yaoqing/info");
            die;
           }
        $this->UserInfo=$UserInfo;
        $this->display();
      }else{
        $this->redirect("/Weixin/Index/getInfo");
      }
     
     }
	      	
	}